<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="xbsj-labels" content="Earth示例"></meta>
    <title>效果-泛光2</title>
    <!-- 0 引入js文件：XbsjEarth.js和vue.min.js -->
    <script src="../../XbsjEarth/XbsjEarth.js"></script>
    <script src="./scripts/vue.min.js"></script>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .defultbtn {
            display: inline-block;
            text-align: center;
            min-width: 60px;
            height: 38px;
            padding: 0 10px;
            line-height: 38px;
            border-radius: 100px;
            border: 1px solid #C9C9C9;
            background-color: #FFF;
            color: #555;
            cursor: pointer;
        }

        .defultbtn:hover {
            background-color: #b3daf8;
        }
    </style>
</head>

<body>
    <div id="vueApp" style="width: 100%; height: 100%; background: grey; position: relative;">
        <earth-comp></earth-comp>
    </div>

    <script>
        // 1 创建Earth的vue组件
        var EarthComp = {
            template: `
                <div style="width: 100%; height: 100%">
                    <div ref="earthContainer" style="width: 100%; height: 100%">
                    </div>
                    <div class="box" style="position: absolute; left: 18px; top: 18px; color: white; border-radius: 25px;min-width:200px; font-size:24px; font-family: 宋体;">
                        <div class="defultbtn" @click="flyTo">定位</div>
                    </div>
                </div>
            `,

            data() {
                return {
                    _earth: undefined, // 注意：Earth和Cesium的相关变量放在vue中，必须使用下划线作为前缀！
                };
            },
            // 1.1 资源创建
            mounted() {
                // 1.1.1 创建地球
                var earth = new XE.Earth(this.$refs.earthContainer);

                // 1.1.2 场景配置
                earth.sceneTree.root = {
                    "expand": true,
                    "title": "预览场景",
                    "children": [
                        {
                            "czmObject": {
                                "xbsjType": "Imagery",
                                "name": "百度暗色风格",
                                "xbsjImageryProvider": {
                                    "XbsjImageryProvider": {
                                        "url": "//api0.map.bdimg.com/customimage/tile?=&x={x}&y={y}&z={z}&scale=1&customid=midnight",
                                        "srcCoordType": "BD09",
                                        "dstCoordType": "WGS84",
                                        "rectangle": [
                                            -3.141592653589793,
                                            -1.5707963267948966,
                                            3.141592653589793,
                                            1.5707963267948966
                                        ]
                                    },
                                }
                            }
                        },
                        {
                            "czmObject": {
                                "xbsjType": "Tileset",
                                "name": "白模测试",
                                "url": "//lab.earthsdk.com/model/908311a0ac2f11e99dbd8fd044883638/tileset.json",
                                "luminanceAtZenith": 1.6, // 提高亮度
                                "xbsjPosition": [
                                    2.120577669988032,
                                    0.545203009169497,
                                    9.313225746154785e-10
                                ],
                            }
                        }
                    ]
                };

                earth.camera.position = [2.1204784429287287, 0.5453567434019185, 984.8776452043272];
                earth.camera.rotation = [2.6041692528943043, -0.8105587768466127, 0.002203744534782004];       

                const tileset1 = earth.sceneTree.root.children[1].czmObject;

                earth.postProcess.bloom.enabled = true; // 开启泛光

                // 1.1.5 数据绑定
                this._tileset = tileset1;
                this._earth = earth;

                // only for debug
                window.earth = this._earth;
                window.tileset1 = this._tileset;
            },
            // 1.2 资源销毁
            beforeDestroy() {
                // vue程序销毁时，需要清理相关资源
                this._earth = this._earth && this._earth.destroy();
            },
            methods: {
                flyTo() {
                    earth.camera.position = [2.1204784429287287, 0.5453567434019185, 984.8776452043272];
                    earth.camera.rotation = [2.6041692528943043, -0.8105587768466127, 0.002203744534782004];    
                }
            }
        }

        // 2 创建vue程序
        // XE.ready()用来加载Cesium.js等相关资源
        XE.ready().then(() => {
            var app = new Vue({
                el: '#vueApp',
                components: {
                    EarthComp,
                },
            });
        });
    </script>
</body>

</html>